package com.twq.collection.list.highorder

/**
 * Created by tangweiqun on 2017/12/10.
 */
object Third {
  def main(args: Array[String]): Unit = {
    //1、Predicates over lists: forall and exists
    //T => Boolean
    List(-1, -2, -3).forall(_ < 0)
    List(-1, -2, -3).exists(i => i > 0)

    def hasZeroRow(m: List[List[Int]]): Boolean =
      m exists (row => row forall (_ == 0))

    val diag3 =
      List(
        List(1, 0, 0),
        List(0, 0, 0),
        List(0, 0, 1)
      )

    hasZeroRow(diag3)

    //2、Sorting lists: sortWith
    List(1, -3, 4, 2, 6) sortWith ((a: Int, b: Int) => a > b)

    val words = List("the", "quick", "brown", "fox")
    words sortWith (_.length > _.length)
  }
}
